/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DLHistory.java
 *
 * Created on Aug 31, 2010, 12:00:18 PM
 */

package Gui;

import BusinessLogic.ExhibitorManagement;
import DTO.Booth;
import DTO.Exhibitor;
import DTO.Product;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author SONY
 */
public class DLHistory extends javax.swing.JDialog {

    private Exhibitor exhibitor;
    private ExhibitorManagement exMag;
    private Vector<String> listYear;
    private Vector<Booth> listBooth;
    private Vector<Product> listProduct;

    /** Creates new form DLHistory */
    public DLHistory(java.awt.Frame parent, boolean modal, ExhibitorManagement exMag, Exhibitor exhibitor) {
        super(parent, modal);
        this.exhibitor = exhibitor;
        this.exMag = exMag;
        
        initComponents();
        //setlocation for application
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension dim = toolkit.getScreenSize();
        Dimension dimApp = getSize();
        int pointX = (dim.width - dimApp.width)/2;
        int pointY = (dim.height - dimApp.height)/2 - 10;
        setLocation(pointX, pointY);

        //
        loadYearOfEx();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tpHistory = new javax.swing.JTabbedPane();
        pnBooth = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbBooth = new javax.swing.JTable();
        pnProduct = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbProduct = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        cbYear = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        pnBooth.setBackground(new java.awt.Color(255, 255, 255));

        tbBooth.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tbBooth);

        javax.swing.GroupLayout pnBoothLayout = new javax.swing.GroupLayout(pnBooth);
        pnBooth.setLayout(pnBoothLayout);
        pnBoothLayout.setHorizontalGroup(
            pnBoothLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
        );
        pnBoothLayout.setVerticalGroup(
            pnBoothLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnBoothLayout.createSequentialGroup()
                .addContainerGap(46, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        tpHistory.addTab("Booth", pnBooth);

        pnProduct.setBackground(new java.awt.Color(255, 255, 255));

        tbProduct.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tbProduct);

        javax.swing.GroupLayout pnProductLayout = new javax.swing.GroupLayout(pnProduct);
        pnProduct.setLayout(pnProductLayout);
        pnProductLayout.setHorizontalGroup(
            pnProductLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 522, Short.MAX_VALUE)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
        );
        pnProductLayout.setVerticalGroup(
            pnProductLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 253, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnProductLayout.createSequentialGroup()
                .addContainerGap(46, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        tpHistory.addTab("Product", pnProduct);

        jLabel1.setText("Year:");

        cbYear.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbYear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbYearActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tpHistory, javax.swing.GroupLayout.PREFERRED_SIZE, 527, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(cbYear, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cbYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(tpHistory, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbYearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbYearActionPerformed
        // TODO add your handling code here:
        JComboBox cb = (JComboBox)evt.getSource();
        String year = (String)cb.getSelectedItem();
        //
        disByYear(year);
    }//GEN-LAST:event_cbYearActionPerformed

    public void loadYearOfEx(){
        listYear = exMag.YearOfEx(exhibitor.getId());
        cbYear.setModel(new DefaultComboBoxModel(listYear));
        //display list booth, product by year
        disByYear(listYear.get(0));
    }

    public void disByYear(String year){
        //load listbooth and list product by year
        listBooth = exMag.BoothByYear(exhibitor.getId() ,year);
        listProduct = exMag.ProductByYear(exhibitor.getId() ,year);
        //display table
        setModelBooth();
        setModelProduct();
    }

    public void setModelProduct(){
        DefaultTableModel model = new DefaultTableModel(null, new Object[]{"IDProduct", "Name", "Description", "dateCreate"});
        tbProduct.setModel(model);

        for(Product p : listProduct){
            Vector rowData = new Vector();
            rowData.add(p.getId());
            rowData.add(p.getName());
            rowData.add(p.getDecription());
            rowData.add(p.getDateCreate());

            model.addRow(rowData);
        }
    }

    public void setModelBooth(){
        DefaultTableModel model = new DefaultTableModel(null, new Object[]{"IDBooth", "Name", "Sponsor", "NumberStaff", "Priority", "Money Service", "Date Create"});
        tbBooth.setModel(model);

        for(Booth b : listBooth){
            Vector rowData = new Vector();
            rowData.add(b.getId());
            rowData.add(b.getName());
            rowData.add(b.getSponsor());
            rowData.add(b.getNumberStaff());
            rowData.add(b.getPriority());
            rowData.add(b.getMoneyService());
            rowData.add(b.getDateCreate());

            model.addRow(rowData);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbYear;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPanel pnBooth;
    private javax.swing.JPanel pnProduct;
    private javax.swing.JTable tbBooth;
    private javax.swing.JTable tbProduct;
    private javax.swing.JTabbedPane tpHistory;
    // End of variables declaration//GEN-END:variables

}
